package com.jsgt.greekfire.ui.pool.adapter

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.fhx.core.utils.ToastUtils
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.MinerBean

/**
 * 矿工适配器
 */
class MinerAdapter : BaseAdapter<MinerBean>() {

    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_miner, parent, false)
        return VH(view)
    }

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var miner_id_tv: TextView? = null
        var miner_coin_tv: TextView? = null
        var miner_address_tv: TextView? = null
        var miner_team_coin_tv: TextView? = null
        var miner_time_tv: TextView? = null
        var miner_copy_tv: TextView? = null
        var miner_team_num_tv: TextView? = null
        var miner_team_device_tv: TextView? = null

        init {
            miner_id_tv = itemView.findViewById(R.id.miner_id_tv)
//            miner_coin_tv = itemView.findViewById(R.id.miner_coin_tv)
            miner_address_tv = itemView.findViewById(R.id.miner_address_tv)
//            miner_team_coin_tv = itemView.findViewById(R.id.miner_team_coin_tv)
//            miner_time_tv = itemView.findViewById(R.id.miner_time_tv)
//            miner_copy_tv = itemView.findViewById(R.id.miner_copy_tv)
//            miner_team_num_tv = itemView.findViewById(R.id.miner_team_num_tv)
//            miner_team_device_tv = itemView.findViewById(R.id.miner_team_device_tv)
        }

        fun bindData(bean: MinerBean) {
            miner_id_tv?.text = bean.walletName.toString()
            miner_address_tv?.text = bean.utiAddress.toString()

//            miner_time_tv?.text =
//                "" + DateFormatUtil.formatNew(bean.createdAt, DateFormatUtil.FORMAT_COMMON)
//            miner_id_tv?.text = "矿工名：" + bean.walletName
//            miner_coin_tv?.text = "持币数量：" + bean.warehouse
//            miner_team_num_tv?.text = "激活数量：" + bean.teamNum
//            miner_team_device_tv?.text = "设备数量：" + bean.teamDeviceNum
//            miner_address_tv?.text =
//                Html.fromHtml("持币地址：<font color= '#F0CF51'>${}</font>")
//            miner_team_coin_tv?.text = "团队持币量：" + bean.teamWarehouse
//            miner_copy_tv?.setOnClickListener {
//                copy(itemView.context, bean.utiAddress!!)
//            }
        }
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        viewHolder.bindData(dataList()[position])
    }

    fun copy(context: Context, content: String) {
        val cm = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
        val mClipData = ClipData.newPlainText("Label", content)
        cm.setPrimaryClip(mClipData)
        ToastUtils.show(context, "复制成功")
    }
}